package day05;
//1. Addition随机加法运算器：由系统随机出10道加法题，
// 而后由用户来答题，答题后输出"答对了"或"答错了"，答对1题得10分，答错1题不扣分,最后输出总分数。

import jdk.nashorn.internal.ir.CaseNode;

import java.lang.reflect.Type;
import java.util.Random;
import java.util.Scanner;
//利用随机数type,可以随机生成加减法算数题
public class Addition {
    public static void main(String[] args) {
        System.out.println("-----欢迎参加百位数加减法考试-----");
        System.out.println("-----本次测试共十题-----");
        Random r = new Random();
        Scanner sc = new Scanner(System.in);
        int score = 0;
        int answer;
        for (int i = 1; i <= 10; i++) {
            int type = r.nextInt(2) + 1;
            if (type == 1) {
                int add = setAddition();
                answer = sc.nextInt();
                if (answer == add) {
                    System.out.println("答对了");
                    score += 10;
                } else {
                    System.out.println("答错了");
                }
            } else {
                int sub = setSubtraction();
                answer = sc.nextInt();
                if (answer == sub) {
                    System.out.println("答对了");
                    score += 10;
                } else {
                    System.out.println("答错了");
                }
            }
        }

        System.out.println("你的最终成绩为:" + score);
    }

    public static int setAddition() {
        Random r = new Random();
        int num1 = r.nextInt(100) + 1;
        int num2 = r.nextInt(100) + 1;
        System.out.println(num1 + "+" + num2 + "=?");
        return num1 + num2;
    }

    public static int setSubtraction() {
        Random r = new Random();
        int num1 = r.nextInt(100) + 1;
        int num2 = r.nextInt(100) + 1;
        System.out.println(num1 + "-" + num2 + "=?");
        return num1 - num2;
    }
}
